package com.geline.demo.config;

import com.baomidou.mybatisplus.extension.service.IService;
import com.geline.demo.service.ExcelFileService;
import com.geline.easyexcel.interfaces.ExcelFileDao;
import com.geline.easyexcel.interfaces.ExcelValidFunction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

/**
 * Excel导入导出处理类
 *
 * @author: mengxin
 * @date: 2024/1/2 9:49
 */
@Component
@Slf4j
public class MyExcelCrudConsumer extends MPExcelCrudConsumer {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private ExcelFileDao excelFileDao;
    @Autowired
    private ExcelFileService excelFileService;
    @Autowired
    private ExcelValidFunction validFunction;

    @Override
    public IService getIService(String entityName) {
        return excelFileService;
    }

    @Override
    public void transLabelToKey(Collection entityList) {
        //处理字典翻译
        easyTransService.transBatch(entityList);
    }

    @Override
    public void transKeyToLabel(Collection entityList) {
        //处理字典翻译
        easyTransService.transBatch(entityList);
    }

    @Override
    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    @Override
    public ExcelFileDao getExcelFileDao() {
        return excelFileDao;
    }

    @Override
    public List handleReportData(List dataList) {
        //处理字典翻译、行政区划翻译
        transKeyToLabel(dataList);
        return dataList;
    }

    @Override
    public ExcelValidFunction getValidFunction() {
        //自定义检验类
        return validFunction;
    }
}
